package com.wish.wishhouse_resource.controller;

import com.wish.wishhouse_resource.util.OssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("oss")
public class UploadController {

    @Autowired
    OssUtil ossUtil;

    @RequestMapping("upload")
    public String uploadFile(MultipartFile file) throws IOException {
        return ossUtil.uploadFile(file);
    }

    @RequestMapping("/uploadFiles")
    public List<String> uploadDocumentFiles(MultipartFile[] files) throws IOException {
        List<String> list = new ArrayList<>();
        for (MultipartFile file:files) {
            String uploadFile = ossUtil.uploadFile(file);
            list.add(uploadFile);
        }
        return list;
    }
}
